//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.UIDesigner.Monitor
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Microsoft.Research.DataLayer;

    /// <summary>
    /// This class abstracts the DataProduct for Visual binding purpose
    /// </summary>
    public class DataProductItem 
    {
        /// <summary>
        /// Original data product
        /// </summary>
        private DataProduct originalDataProduct;

        /// <summary>
        /// HTML file path of the generated data product
        /// </summary>
        private string htmlPath;

        /// <summary>
        /// Initializes a new instance of the DataProductItem class.
        /// </summary>
        /// <param name="dataProduct">the original data product</param>
        /// <param name="htmlPath">HTML file path where the data product is writen</param>
        /// <exception cref="System.ArgumentNullException">if <paramref name="dataProduct"/> is null</exception>
        public DataProductItem(DataProduct dataProduct, string htmlPath)
        {
            if (dataProduct == null)
            {
                throw new ArgumentNullException("dataProduct");
            }

            if (htmlPath == null)
            {
                throw new ArgumentNullException("htmlPath");
            }

            if (htmlPath.Length == 0)
            {
                throw new ArgumentNullException("htmlPath");
            }

            this.originalDataProduct = dataProduct;
            this.htmlPath = htmlPath;
        }

        /// <summary>
        /// Gets the data product name
        /// </summary>
        public string Name
        {
            get { return this.originalDataProduct.Name; }
        }

        /// <summary>
        /// Gets the data product type
        /// </summary>
        public string ProductType
        {
            get { return this.originalDataProduct.Type; }
        }

        /// <summary>
        /// Gets the BitmapImage object for the type
        /// </summary>
        public BitmapImage ImageSource
        {
            get
            {
                string extension = DataProductIconBuilder.ProductTypeExtensions[this.originalDataProduct.Type];
                return DataProductIconBuilder.FileTypeIcons[extension];
            }
        }

        /// <summary>
        /// Gets the orginal data product
        /// </summary>
        public DataProduct OriginalDataProduct
        {
            get { return this.originalDataProduct; }
        }

        /// <summary>
        /// Gets the HTML file path of the generated data product
        /// </summary>
        public string HtmlPath
        {
            get { return this.htmlPath; }
        }

        /// <summary>
        /// Overridden tostring method. For automation Ids.
        /// </summary>
        /// <returns>The string representation of the object.</returns>
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(this.Name))
            {
                return this.Name;
            }
            return base.ToString();
        }
    }
}
